*************************
clear all
set more off
capture log close
set logtype text
cd t:\vega\kilian_vega
set memory 600m
set matsize 400
**************************
log using test2, replace
log close

use wti_clean, clear

global numvar=0

*create matrix of results, with one row and 20 columns for each horizon
foreach num of numlist 26 27 28 1 7 9 11 10 19 21 17 18 3 13 15 12 20 6 8 34 2 33 71 72 14 16 4 5 32 25 {
global numvar=`num'
matrix results$numvar=J(1,240,.)
}


sort date
save wti, replace
	use mms_all_final2, clear
	sort date

	
	merge date using wti		
	sort date
	**copy down price if it is missing
	sort date
	gen date_ch=date-date[_n-1]

	replace wti=wti[_n-1] if wti==. & date_ch<=6
	drop if wti==.

	***generate pric_ch at different horizons
	*forvalues i=1/20 {
	forvalues i=1/240 {

		gen price_ch_`i'd=100*(log(wti[_n+`i'])-log(wti[_n-1]))
		*positive sign
		foreach num of numlist 26 27 28 7 9 11 10 19 21 17 18 3 13 15 20 6 8 34 2 33 71 72 14 16 4 5 1 12 32 25 {
		global numvar=`num'
		reg price_ch_`i'd surs`num', robust
		global obs=e(N)
		matrix V=e(V)
		global tstat=abs(round(_b[surs`num']/sqrt(V[1,1]),0.01))
		gen res=($tstat>=1)
		mat results$numvar[1,`i']=res[1]
		drop res
		}
		


}

matrix results=results26
foreach num of numlist 27 28 1 7 9 11 10 19 21 17 18 3 13 15 12 20 6 8 34 2 33 71 72 14 16 4 5 32 25 {

matrix results=results\results`num'
}

log using test2, replace
matlist results
log close

